package com.psp.web.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.psp.web.model.UserMsgBean;
import com.psp.web.persist.dao.UserMsgDao;
import com.psp.web.service.exception.ServiceException;

@Repository
public class UserMsgImpl extends BaseImpl implements UserMsgDao {
	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".UserMsgMapper";

	@Override
	public List<UserMsgBean> selectList(int page, int pageSize, String sid, String tid, Integer type, Integer msgType) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		where.put("sid", sid);
		where.put("tid", tid);
		where.put("type", type);
		where.put("msgType", msgType);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public int selectCount(String sid, String tid, Integer type, Integer msgType) {
		Map<String, Object> where = new HashMap<>();
		where.put("sid", sid);
		where.put("tid", tid);
		where.put("type", type);
		where.put("msgType", msgType);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", where);
	}

	@Override
	public UserMsgBean selectById(Long id) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectById", id);
	}

	@Override
	public int delete(Long id) throws ServiceException {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", id);
	}

}
